export default {
  data() {
    return {}
  },
  methods: {
    wechatPay(options) {
      return new Promise((resolved, rejected) => {
        wx.requestPayment({
          nonceStr: options.nonceStr,
          // package: "prepay_id=" + options.prepay_id,
          package: options.packageValue,
          // paySign: options.paySign + "==",
          paySign: options.paySign,
          timeStamp: options.timeStamp,
          signType: "RSA",
          "success": (res) => {
          },
          "fail": (err) => {
            console.log(err);
          },
          "complete": (finish) => {
            rejected(finish);
          }
        })
      })
    },

    countDown(start, end) {
      let time = new Date(start.replace(/\-/g, '/')).getTime();
      let endtime = end ? new Date(end.replace(/\-/g, '/')).getTime() :null;
      let now = new Date().getTime();
      let differ = end ? ((endtime - time) / 1000) : ((now - time) / 1000);
      if (differ >= 0) {
        let d = Math.floor(differ / (60 * 60 * 24));
        let h = Math.floor(differ / (60 * 60) % 24) + d * 24;
        let m = Math.floor(differ / 60 % 60);
        let s = Math.floor(differ % 60);
        let hour = h < 10 ? `0${h}` : h;
        let minute = m < 10 ? `0${m}` : m;
        let second = s < 10 ? `0${s}` : s;
        return {
          hour: hour,
          minute: minute,
          second: second
        };
      }
      return {
        hour: '00',
        minute: '00',
        second: '00'
      }
    },
    goback() {
      let pages = getCurrentPages(); // 当前页面
      let page = getCurrentPages().pop(); // 当前页面
      let beforePage = pages[pages.length - 2]; // 上一页
      uni.navigateBack({
        success: () => {
          beforePage.onLoad(page.options); // 执行上一页的onLoad方法
        }
      });
    }
  }
}
